// yb_mingpian/pages/ruzhu/guanli.js
var t = getApp(),
  a = t.requirejs("core"),
  s = t.requirejs("wxParse/wxParse");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    express_name:'',
    co_id:'',
    obj: [],
    id:[],
		isActive : 1,
    my_goods:[],
    state:0,
    order_status:0,
    orderinfo:[],
    goodsid:[],
    info:'',
    status: "",
    page: 1,
    list: [],
    order_id:'',
    send:false,
    wuliu:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.getdata()
    var that=this
    console.log(options.id)
    that.setData({
      state: options.id
    })
    that.getdata()
    that.getwuliuliebiao()
    console.log(that.data.state)
  },
  getdata: function(){
    var o = this
     a.get("Card/MyOrder", {
        uid: getApp().getCache("userinfo").uid,
        order_status: o.data.order_status,
      }, function (res) {
        console.log(res)
        o.setData({
          orderinfo : res.orderinfo
        })
        o.setData({
          info : res.info
        })
        o.setData({
          code : res.code
        })
        // console.log(o.data.orderinfo)
      })
      
  },
	Aclick : function(){
		this.setData({
			      isActive: 1
			    })
    this.setData({
      order_status: 0
    })
    // this.setData({
    //   state: 0
    // })
    this.getdata()
    this.quxiao()
	}
	,
	Aclick1 : function(){
		this.setData({
			      isActive: 2
			    })
    this.setData({
      order_status: 1
    })
    // this.setData({
    //   state: 1
    // })
   
    this.getdata()
	},
	Aclick2 : function(){
		this.setData({
			      isActive: 3
			    })
	  this.setData({
	    order_status: 2
    })
    // this.setData({
    //   state: 2
    // })
    this.getdata()
    this.quxiao()
	},
	Aclick3 : function(){
		this.setData({
			      isActive: 4
			    })
	  this.setData({
	    order_status: 3
    })
    // this.setData({
    //   state: 3
    // })
    this.getdata()
    this.quxiao()
  },
  quxiao:function(){
    this.setData({
	    send: false
    })
  },
  send:function(e){
    this.setData({
	    send: true
    })
    let orderid = e.currentTarget.dataset.order_id
      console.log(orderid)
      this.setData({
        orderid: orderid
      })
  },
  fanhui:function(){
    this.setData({
	    wuliu: false
    })
  },
  tianjia:function(){
    this.setData({
	    wuliu: true
    })
  },
  toxiangqing: function(e){
    let order_id = e.currentTarget.dataset.order_id
    console.log(order_id)
    this.setData({
	    orderid: order_id
    })
    wx.navigateTo({
      url: '/yb_mingpian/pages/ruzhu/xiangqing?id='+order_id,
    })
  },
  getwuliuliebiao: function () {
    var o = this
     a.get("Card/expressList", {
      }, function (res) {
        console.log(res)
        o.setData({
          express_company : res.express_company
        })
        console.log(o.data.express_company)
        let obj =[]
        let id =[]
      for(let i = 0;i<o.data.express_company.length; i++ ) {
        obj[i] = o.data.express_company[i].company_name
      }
      for(let i = 0;i<o.data.express_company.length; i++ ) {
        id[i] = o.data.express_company[i].co_id
      }
      o.setData({
        obj :obj
      })
      o.setData({
        id :id
      })
      console.log(o.data.obj)
      console.log(o.data.id)
      })
    },
    kuaidi:function(e){
      var o = this
      console.log(o.data.orderid)
    a.get("Card/DeliveryOrder",{
      orderid:o.data.orderid,
      shipping_type: 0,
    },function (res) {
     wx.showToast({
       title: res.info,
     })
     wx.navigateTo({
      url: '/yb_mingpian/pages/ruzhu/store',
    })
    })
    },
  Inputexpress_no(e){
    this.setData({
      express_no: e.detail.value
    })
  // console.log(this.data.tel);
},
    fahuo:function(e){
      var o = this
      if ( o.data.co_id == undefined) {
        wx.showToast({
          title: '请选择快递公司',
          icon: 'none',
        })
        return
      }
      if ( o.data.express_no == undefined) {
        wx.showToast({
          title: '请输入物流单号',
          icon: 'none',
        })
        return
      }
      console.log(o.data.orderid)
      console.log(o.data.express_name)
      console.log(o.data.co_id)
      console.log(o.data.express_no)
    a.get("Card/DeliveryOrder",{
      orderid:o.data.orderid,
      shipping_type: 1,
      express_name:o.data.express_name,
      express_company_id:o.data.co_id,
      express_no:o.data.express_no,
    },function (res) {
     wx.showToast({
       title: res.info,
     })
     wx.navigateTo({
       url: '/yb_mingpian/pages/ruzhu/store',
     })
    })
    },
    bindPickerChange: function(e) {
      let o = this
      // console.log('picker发送选择改变，携带值为', e.detail.value)
      this.setData({
        index: e.detail.value
      })
      this.setData({
        co_id: o.data.id[e.detail.value]
      })
      this.setData({
        express_name: o.data.obj[e.detail.value]
      })
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    //  this.Aclick3()
    if (this.data.state == 0) {
      console.log(0)
      this.Aclick()
    }
    if (this.data.state == 1) {
      console.log(1)
      this.Aclick1()
    }
    if (this.data.state == 2) {
      console.log(2)
      this.Aclick2()
    }
    if (this.data.state == 3) {
      console.log(3)
      this.Aclick3()
    }
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})